function fig = plot_causal_fir(modelstr,FD,N,i0,hApprox,hIdeal)
fig = figure;
wIndex = (-floor((N-1)/2):floor(N/2))';

plot_ideal = nargin==6;

subplot(2,1,1);
hold on;

stem(wIndex,hApprox)

fill([wIndex(1)-0.5 0 0 wIndex(1)-0.5], [1.2 1.2 -1 -1],[1 0 0],'FaceAlpha',0.1,'EdgeColor',"none");
fill([0 wIndex(end)+0.5 wIndex(end)+0.5 0], [1.2 1.2 -1 -1],[0 0 1],'FaceAlpha',0.1,'EdgeColor',"none");

if plot_ideal
    n = (-20:20)';
    t = linspace(n(1),n(end),1024);
    scatter(n,hIdeal(n),10,'k','filled','MarkerFaceAlpha',0.4); 
    plot(t,hIdeal(t),'LineWidth',0.5,'Color',[0.5 0.5 0.5]);
end

xline(FD,'Color','b','LineStyle','--')

hold off;
xlabel('Sample Index'); 
ylabel('FIR Coefficients'); 
ylim([-0.5,1]);
xlim([-1.5*N,1.5*N]);


annotarrow([-1,FD],[0.5,0.1],'FD');

if plot_ideal
    legend('Truncated FIR','Anti-Causal Indices','Causal Indices','Ideal Filter')
    title(modelstr+"-based Fractional Delay Non-Causal FIR, Truncated on ["+num2str(wIndex(1))+":"+num2str(wIndex(end))+"]");
else
    legend('FIR','Anti-Causal Indices','Causal Indices')
    title(modelstr+"-based Fractional Delay Non-Causal FIR, Supported on ["+num2str(wIndex(1))+":"+num2str(wIndex(end))+"]");
end



subplot(2,1,2);
hold on;
stem(wIndex+i0,hApprox)
fill(i0+[wIndex(1) N/2+0.5 N/2+0.5 wIndex(1)], [1.2 1.2 -1 -1],[0 0 1],'FaceAlpha',0.1,'EdgeColor',"none");

xline(i0+FD,'Color','b','LineStyle','--')

hold off;

if plot_ideal
    legend('Truncated Causal FIR','All Causal Indices')
    title("Causal Shift of "+modelstr+"-based Fractional Delay FIR, Truncated on ["+num2str(0)+":"+num2str(N-1)+"]")
else
    legend('Causal FIR','All Causal Indices')
    title("Causal Shift of "+ modelstr+"-based Fractional Delay FIR, Supported on ["+num2str(0)+":"+num2str(N-1)+"]")
end

xlabel('Sample Index'); 
ylabel('FIR Coefficients'); 
ylim([-0.5,1]);
xlim([-1.5*N,1.5*N]);
annotarrow([-1,i0+FD],[0.5,0.1],'i_0+FD');

end

%%
% Annotate text arrow
function annotarrow(x,y,str)
    pos = get(gca,'Position');
    lx = xlim(gca);
    ly = ylim(gca);
    
    % Normalized cooridnates
    nx = pos(1)+pos(3)*(x-lx(1))/diff(lx);
    ny = pos(2)+pos(4)*(y-ly(1))/diff(ly);
    
    annotation('textarrow',nx,ny,'String',str)
end